// $Id$
package de.servicezombie.cxf;

import de.servicezombie.lang.WrappedException;

public class WebserviceTemplateFactory extends AbstractWebserviceTemplateFactory {
	
	public static class Cxf24ShopWebserviceTemplateProvider implements WebserviceTemplateProvider {

		public WebserviceTemplate getWebserviceTemplate() {
			return new WebserviceTemplateCxf24Impl();
		}

	}

	// reflection method is needed for better unit testing
	
	public static Class<? extends WebserviceTemplateProvider> providerClass = Cxf24ShopWebserviceTemplateProvider.class;
	
	public static void setProviderClass(Class<? extends WebserviceTemplateProvider> providerClass) {
		WebserviceTemplateFactory.providerClass = providerClass;
	}
	
	private static WebserviceTemplateProvider decideAndBuildProvider() {
		
		if(providerClass == null) {
			throw new IllegalArgumentException("Set providerClass property to build a provider instance");
		}
		
		WebserviceTemplateProvider result;
		
		try {
			result = providerClass.newInstance();
		}
		catch (InstantiationException e) {
			throw new WrappedException(e);
		}
		catch (IllegalAccessException e) {
			throw new WrappedException(e);
		} 
		
		return result;
	}
	
	public WebserviceTemplateFactory() {
		super(decideAndBuildProvider());
	}

}
